package com.hopu.blb_erp.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.hopu.blb_erp.mapper.OrganizationMapper;
import com.hopu.blb_erp.entity.Organization;
import com.hopu.blb_erp.entity.PageEntity;
import com.hopu.blb_erp.service.OrganizationService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class OrganizationServiceImpl extends ServiceImpl<OrganizationMapper,Organization> implements OrganizationService {

    @Autowired
    private OrganizationMapper organizationMapper;

    @Override
    public Integer findCount() {
        return organizationMapper.selectCount();
    }

    @Override
    public PageEntity<Organization> findPage(Integer current, Integer length) {
        Integer count = organizationMapper.selectCount();
        List<Organization> organizations = organizationMapper.selectPage((current - 1) * length, length);
        PageEntity<Organization> organizationPageEntity = new PageEntity<>();
        organizationPageEntity.setData(organizations);
        organizationPageEntity.setCurrent(current);
        organizationPageEntity.setCount(count);
        return organizationPageEntity;
    }
}
